package com.jie.common.util;

import lombok.extern.slf4j.Slf4j;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;


@Slf4j
public class InputStreamUtil {

    public static String inputStreamConvertString(InputStream is) {
        ByteArrayOutputStream baos = null;
        String result = null;
        try {
            if(is != null) {
                baos = new ByteArrayOutputStream();
                int i;
                while ((i = is.read()) != -1) {
                    baos.write(i);
                }
                result = baos.toString();
            }
        } catch (IOException e) {
            log.error("字符流读取异常 {}", e.toString());
        } finally {
            if(baos != null) {
                try {
                    baos.close();
                } catch (IOException e) {
                    log.error("关闭流失败！");
                }
            }
        }
        return result;
    }

}
